<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05员工表格练习</title>
</head>
<body>
<input type="text" placeholder="请输入员工姓名" id="i1">
<input type="text" placeholder="请输入员工工资" id="i2">
<input type="text" placeholder="请输入员工岗位" id="i3">
<button onclick="addEmp()">点我添加员工</button>
<hr>
<table border="1">
    <caption>员工表</caption>
    <tr>
        <td>姓名</td>
        <td>工资</td>
        <td>岗位</td>
    </tr>
</table>

<script>
    function addEmp(){
        //首先获取用户输入的3个值
        let uname = document.querySelector('#i1').value;
        let usalary = document.querySelector('#i2').value;
        let ujob = document.querySelector('#i3').value;
        console.log(uname,usalary,ujob);
        // 创建tr标签和3个td，并把3个值写入到td标签中
        let tr = document.createElement('tr');
        let nameTd = document.createElement('td');
        let salaryTd = document.createElement('td');
        let jobTd = document.createElement('td');
        console.log(nameTd,salaryTd,jobTd);
        //把获取到的数据填充到单元格中
        nameTd.innerHTML = uname;
        salaryTd.innerHTML = usalary;
        jobTd.innerHTML = ujob;
        //把准备好的3个td装入到tr
        tr.append(nameTd,salaryTd,jobTd);
        document.querySelector('table').append(tr);
        //每个输入框的数据清空
        document.getElementById('i1').value="";
        document.getElementById('i2').value="";
        document.getElementById('i3').value="";
    }
</script>
</body>
</html>